﻿Imports System.Data
Imports System.Data.SqlClient
Public Class MovimentoContasDAL
#Region "Métodos"
    Function inserirConta(ByVal codigo As Integer, ByVal opera As String, ByVal dtemiss As Date, ByVal ccc As Integer, ByVal concod As Integer, ByVal pagcod As Integer, ByVal docref As String, ByVal bolcheque As String,
                          ByVal dtlancam As Date, ByVal val As Decimal, ByVal obse As String) As Integer
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            cmd.CommandText = "execute SPContas @codigo,@operacao,@dtemissao,@ccccodigo,@concodigo,@pagcodigo,@docreferencia,@bolcheque,@dtlancamento,@valor,@obs"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            cmd.Parameters.Add(New SqlParameter("@operacao", SqlDbType.VarChar)).Value = opera
            cmd.Parameters.Add(New SqlParameter("@dtemissao", SqlDbType.Date)).Value = dtemiss
            cmd.Parameters.Add(New SqlParameter("@ccccodigo", SqlDbType.Int)).Value = ccc
            cmd.Parameters.Add(New SqlParameter("@concodigo", SqlDbType.Int)).Value = concod
            cmd.Parameters.Add(New SqlParameter("@pagcodigo", SqlDbType.Int)).Value = pagcod
            cmd.Parameters.Add(New SqlParameter("@docreferencia", SqlDbType.VarChar)).Value = docref
            cmd.Parameters.Add(New SqlParameter("@bolcheque", SqlDbType.VarChar)).Value = bolcheque
            cmd.Parameters.Add(New SqlParameter("@dtlancamento", SqlDbType.Date)).Value = dtlancam
            cmd.Parameters.Add(New SqlParameter("@valor", SqlDbType.Decimal)).Value = val
            cmd.Parameters.Add(New SqlParameter("@obs", SqlDbType.VarChar)).Value = obse
            codigo = objconexao.executacmdAI(cmd, "ofi_MovimentacaoContas")
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return codigo
    End Function


#End Region
#Region "Localiza"
    Function localizar(ByVal descricao As String, tipo As Integer) As DataTable
        Dim cmd As SqlCommand
        Dim tab As DataTable
        Try
            cmd = New SqlCommand
            Select Case tipo
                Case 0   'ven_codigo
                    cmd.CommandText = "select * from vw_FinContasReceber where ven_codigo = @descricao"
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.Int)).Value = descricao
                Case 1 'Todos
                    cmd.CommandText = "select * from vw_FinContasReceber where icr_codigo = @descricao"
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.Int)).Value = descricao
                Case 2    'por nome cliente
                    cmd.CommandText = "select * from vw_FinContasReceber where cli_nome COLLATE SQL_Latin1_General_CP1_CI_AI like @descricao"
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.VarChar)).Value = "%" & descricao & "%"
                Case 3   'por Status desc
                    cmd.CommandText = "select * from vw_FinContasReceber where sta_descricao COLLATE SQL_Latin1_General_CP1_CI_AI like @descricao order by icr_dtrecebimento "
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.VarChar)).Value = "%" & descricao & "%"
                Case 4 'ctr_codigo
                    cmd.CommandText = "select * from vw_FinContasReceber where ctr_codigo= @descricao and sta_codigo <> 6"
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.Int)).Value = descricao
                Case 5 'visualiza
                    cmd.CommandText = "select cli_nome,icr_parcela,icr_valor,icr_dtvencimento,icr_dtrecebimento,ccc_descricao,sta_descricao from vw_FinContasReceber where ctr_codigo= @descricao"
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.Int)).Value = descricao
                Case 6 'ctr_codigo
                    cmd.CommandText = "select * from Financeiro.Ofi_ContasReceber where ctr_codigo= @descricao"
                    cmd.Parameters.Add(New SqlParameter("@descricao", SqlDbType.Int)).Value = descricao
                Case Else 'geral
                    cmd.CommandText = "select * from vw_FinContasReceber where sta_codigo =4 order by icr_dtvencimento asc"
            End Select
            tab = objconexao.executaConsulta(cmd)
            tab.DefaultView.AllowNew = False
        Catch ex As Exception
            Throw ex
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function
#End Region
    'Function excluir(ByVal codigo As Integer) As Boolean
    '    Dim cmd As SqlCommand
    '    Try
    '        cmd = New SqlCommand
    '        cmd.CommandText = "execute SPExcluiItensContasPagar @codigo"
    '        cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
    '        objconexao.executaCmd(cmd)
    '        Return True
    '    Catch ex As Exception
    '        Throw ex
    '        Return False
    '    Finally
    '        cmd = Nothing
    '    End Try
    'End Function
End Class
